﻿using System;
using System.Collections.Generic;
using System.Text;
using CFSystem.JXC.IDAL;
using CFSystem.JXC.Model;
using System.Data;
using System.Data.OleDb;
using DBUtility;

namespace CFSystem.JXC.AccessDAL
{
    public class Size:ISize 
    {
          public Size()
        { }

        /// <summary>
        /// Method to get all SizeInfo
        /// </summary>		
        /// <returns>Interface to Model Collection Generic of Sizes</returns>
        public IList<SizeInfo> GetSizes()
        {

            string sqlSelect = "SELECT * from tb_Size";

            OleDbDataReader dr = AccessHelper.ExecuteReader(AccessHelper.ConnectionString, CommandType.Text, sqlSelect);

            IList<SizeInfo> SizeItems = new List<SizeInfo>();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    SizeInfo bi = new SizeInfo(Convert.ToInt32(dr[0].ToString()), Convert.ToString(dr[1].ToString()));
                    SizeItems.Add(bi);
                }
                dr.Close();
            }
            return SizeItems;
        }

        /// <summary>
        /// Get information on a specific Size
        /// </summary>
        /// <param name="categoryId">Unique identifier for a Size</param>
        /// <returns>Business Entity representing an Size</returns>
        public SizeInfo GetSize(string SizeID)
        {
            return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="SizeName"></param>
        public void InsertSize(string SizeName)
        {
            string sqlInsert = "insert into [tb_Size]([Name]) values('" + SizeName + "')";

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlInsert);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SizeID"></param>
        public void DelSizeByID(int SizeID)
        {
            string sqlDel = "delete from [tb_Size] where [SizeID]=" + SizeID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlDel);

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SizeID"></param>
        /// <param name="updValue"></param>
        public void UpdateSizeByID(int SizeID, string updValue)
        {
            string sqlUpd = "update [tb_Size] set [Name] ='" + updValue + "'" + " where [SizeID]=" + SizeID;

            int returnCnt = AccessHelper.ExecuteNonQuery(AccessHelper.ConnectionString, CommandType.Text, sqlUpd);

        }
    }
}
